﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FluentFTP.Configuration;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.ViewModel;

namespace FluentFTP.ViewModel
{
    internal class SettingsViewModel : NotificationObject
    {
        #region Properties

        private string defaultUserName;

        public string DefaultUserName
        {
            get { return defaultUserName; }
            set
            {
                defaultUserName = value;
                RaisePropertyChanged(() => DefaultUserName);
            }
        }

        private string defaultPassword;

        public string DefaultPassword
        {
            get { return defaultPassword; }
            set
            {
                defaultPassword = value;
                RaisePropertyChanged(() => DefaultPassword);
            }
        }

        private string defaultSavePath;

        public string DefaultSavePath
        {
            get { return defaultSavePath; }
            set
            {
                defaultSavePath = value;
                RaisePropertyChanged(() => DefaultSavePath);
            }
        }

        #endregion

        #region Commands

        public DelegateCommand SelectDefaultSavePath { get; private set; }
        public DelegateCommand Save { get; private set; }

        #endregion Commands

        public SettingsViewModel()
        {
            DefaultUserName = Settings.UserSettings.DefaultUserName;
            DefaultSavePath = Settings.UserSettings.DefaultSaveFolder;
            DefaultPassword = Settings.UserSettings.DefaultPassword;

            SelectDefaultSavePath = new DelegateCommand(() =>
                {
                    FolderBrowserDialog dialog = new FolderBrowserDialog();
                    dialog.SelectedPath = DefaultSavePath;

                    var result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        DefaultSavePath = dialog.SelectedPath;
                    }
                });

            Save = new DelegateCommand(() =>
                {
                    Settings.UserSettings.DefaultPassword = DefaultPassword;
                    Settings.UserSettings.DefaultSaveFolder = DefaultSavePath;
                    Settings.UserSettings.DefaultUserName = DefaultUserName;
                });
        }
    }
}
